<template>
    <view class="home">
        <view class="item it_flex" @click="yiji()">
            <view class="it_left">选择分类</view>
            <view class="it_right">
                <text>{{ yijiName ? yijiName : "请选择分类" }}</text>
                <image
                    class="it_lef_img"
                    :src="imageURL + '/static/wImg/arrowRig.png'"
                ></image>
            </view>
        </view>
        <view class="item it_flex" @click="show_cate_is = true" v-if="catelist2">
            <view class="it_left">选择二级分类</view>
            <view class="it_right">
                <text>{{ erjiName ? erjiName : "请选择二级分类" }}</text>
                <image
                    class="it_lef_img"
                    :src="imageURL + '/static/wImg/arrowRig.png'"
                ></image>
            </view>
        </view>
        <view class="item it_flex">
            <view class="it_left">商品名称</view>
            <input type="text" placeholder="请输入商品名称" v-model="title" />
        </view>
        <view class="item it_flex">
            <view class="it_left">商品描述</view>
            <input
                type="text"
                placeholder="请输入商品描述"
                v-model="description"
            />
        </view>
        <view class="item it_flex">
            <view class="it_left">商品详情</view>
            <input type="text" placeholder="请输入商品详情" v-model="content" />
        </view>
        <view class="item it_flex" @click="showFenLei = true">
            <view class="it_left">商户内分类</view>
            <view class="it_right">
                <text v-for="(item, index) in catenamelist" :key="index">
                    {{ item }}
                </text>
                <text v-if="catenamelist.length == 0">
                    {{ fenleiName ? fenleiName : "请选择商户内分类" }}
                </text>
                <image
                    class="it_lef_img"
                    :src="imageURL + '/static/wImg/arrowRig.png'"
                ></image>
            </view>
        </view>
        <picker
            :range="postagelist"
            range-key="name"
            label-name="name"
            @change="getPostage"
        >
            <view class="item it_flex">
                <view class="it_left">运费模版</view>
                <view class="it_right">
                    <text>{{
                        postagename ? postagename : "请选择是否包邮"
                    }}</text>
                    <image
                        class="it_lef_img"
                        :src="imageURL + '/static/wImg/arrowRig.png'"
                    ></image>
                </view>
            </view>
        </picker>
        <view class="item it_flex" @click="show_area_is = true">
            <view class="it_left">选择地区</view>
            <view class="it_right">
                <text>{{ ssqName ? ssqName : "请选择地区" }}</text>
                <image
                    class="it_lef_img"
                    :src="imageURL + '/static/wImg/arrowRig.png'"
                ></image>
            </view>
        </view>
        <view class="item item_pad_bot">
            <view class="it_left" style="margin-bottom: 30rpx"
                >上传商品图片</view
            >
            <view class="u-flex u-flex-wrap it_right">
                <view
                    class="it_rig_img"
                    style="position: relative"
                    v-if="imgUrl"
                    v-for="img in imgUrl"
                    :key="img"
                >
                    <image
                        class="it_rig_img"
                        mode="aspectFill"
                        :src="img"
                    ></image>
                </view>
                <view class="it_rig_box" @click="upshopImg">+</view>
            </view>
        </view>
        <view class="item item_pad_bot">
            <view class="it_left" style="margin-bottom: 30rpx"
                >上传商品视频</view
            >
            <view class="u-flex u-flex-wrap it_right">
                <view class="it_rig_box" @click="uplistImg">
                    <image
                        :src="imageURL + '/static/home/video.png'"
                        mode=""
                    ></image>
                </view>
                <view
                    class="it_rig_img"
                    style="position: relative"
                    v-if="videoItem"
                >
                    <block>
                        <video
                            :src="videoItem"
                            class="it_rig_img"
                            controls="false"
                        ></video>
                    </block>
                    <!-- <block v-for="(videoItem, index) in videoItem" :key="index">
						<video :src="videoItem" class="it_rig_img" controls="false"></video>
					</block> -->
                </view>
            </view>
        </view>
        <!-- 多规格 -->
        <view
            class="item item_pad_bot"
            v-for="(item, index) in skuList"
            :key="index"
        >
            <view class="it_tit">
                <view class="it_left">{{ item.title }}</view>
                <view class="u-flex it_grey" @click="skuDel(index)">
                    <image :src="BaseUrl + '/static/wImg/delete.png'"></image>
                    删除
                </view>
            </view>
            <view class="u-flex u-flex-wrap">
                <view
                    class="it_specs"
                    v-for="(items, indexs) in item.skuitem"
                    :key="indexs"
                >
                    <input
                        type="text"
                        v-model="items.name"
                        confirm-type="done"
                        @blur="iptitSpec(indexs)"
                        @confirm="iptitSpec(indexs)"
                    />
                    <image
                        class="it_sp_line"
                        :src="BaseUrl + '/static/wImg/line.png'"
                    ></image>
                    <image
                        class="it_sp_cha"
                        :src="BaseUrl + '/static/wImg/cha.png'"
                        @click="delSpec(indexs, item.skuitem)"
                    ></image>
                </view>
                <view class="it_specs">
                    <image
                        class="it_sp_plus"
                        :src="BaseUrl + '/static/wImg/smaPlus.png'"
                    ></image>
                    <view
                        class="it_sp_gre"
                        @click="addSpec(item.skuitem, index)"
                        >添加新规格</view
                    >
                </view>
            </view>
        </view>
        <view class="item item_pad_bot" v-if="is_add_show">
            <view class="it_tit">
                <input
                    type="text"
                    placeholder="请输入规格类型"
                    confirm-type="done"
                    @blur="iptNewspec"
                    @confirm="iptNewspec"
                    v-model="newSpec"
                />
                <view class="u-flex it_grey" @click="delAdd()">
                    <image :src="BaseUrl + '/static/wImg/delete.png'"></image>
                    删除
                </view>
            </view>
            <view class="u-flex u-flex-wrap">
                <view class="it_specs">
                    <image
                        class="it_sp_plus"
                        :src="BaseUrl + '/static/wImg/smaPlus.png'"
                    ></image>
                    <view class="it_sp_gre">添加新规格</view>
                </view>
            </view>
        </view>
        <view class="item item_pad_bot">
            <view class="it_left">价格</view>
            <view
                class="it_right_duo"
                v-for="(item, index) in PricList"
                :key="index"
            >
                <view class="u-flex u-flex-wrap" style="margin-top: 20rpx">
                    <view
                        class="it_pri"
                        v-for="(items, indexs) in item.temp"
                        :key="indexs"
                        >{{ items }}</view
                    >
                </view>
                <view class="u-flex u-row-between it_rig_line">
                    <view class="it_ban u-flex">
                        <view class="it_left">商品价格</view>
                        <input
                            type="digit"
                            placeholder="请输入价格"
                            v-model="item.price"
                        />
                    </view>
                    <view class="it_ban u-flex">
                        <view class="it_left">设置库存</view>
                        <input
                            type="number"
                            placeholder="请输入库存"
                            v-model="item.kuc"
                        />
                    </view>
                </view>
                <view class="u-flex u-row-between it_rig_line">
                    <view class="it_ban u-flex">
                        <view class="it_left">商品重量</view>
                        <input
                            type="digit"
                            placeholder="请输入重量"
                            v-model="item.weigh"
                        />
                    </view>
                    <view class="it_ban u-flex">
                        <view class="it_left">划线价格</view>
                        <input
                            type="digit"
                            placeholder="请输入划线价格"
                            v-model="item.market_price"
                        />
                    </view>
                </view>
                <view class="u-flex u-row-between it_rig_line">
                    <view class="it_ban u-flex">
                        <view class="it_left">会员价格</view>
                        <input
                            type="digit"
                            placeholder="请输入会员价格"
                            v-model="item.vip_price"
                        />
                    </view>
                    <view class="it_ban u-flex">
                        <view class="it_left">商品编码</view>
                        <input
                            type="digit"
                            placeholder="请输入商品编码"
                            v-model="item.sn"
                        />
                    </view>
                </view>
            </view>
        </view>
        <view class="add u-flex-center" @click="is_add_show = true"
            >新增规格</view
        >
        <view style="height: 60rpx"></view>
        <!-- 多列选择 -->
        <!-- <view class="layer" v-if="is_cate_show" style="z-index: 9999999999">
      <view class="layer-content">
        <view
          class="confirm-bar line-height-80 padding-lr-30 bg-ff border-bottom-ed flex align-center justify-between"
        >
          <view class="text-cc" @click="is_cate_show = false">取消</view>
          <view class="" style="color: #007aff" @click="cateSubmit()"
            >确定</view
          >
        </view>
        <picker-view
          :value="multiIndex"
          :indicator-style="indicatorStyle"
          class="picker-view"
          @change="change"
        >
          <picker-view-column>
            <view
              class="item-pircker"
              v-for="(item, index) in catelist1"
              :key="index"
              >{{ item.name }}</view
            >
          </picker-view-column>
          <picker-view-column v-if="catelist2">
            <view
              class="item-pircker"
              v-for="(item, index) in catelist2"
              :key="index"
              >{{ item.name }}</view
            >
          </picker-view-column>
          <picker-view-column v-if="catelist3">
            <view
              class="item-pircker"
              v-for="(item, index) in catelist3"
              :key="index"
              >{{ item.name }}</view
            >
          </picker-view-column>
        </picker-view>
      </view>
    </view>
    <view class="layer" v-if="is_area_show" style="z-index: 9999999999">
      <view class="layer-content">
        <view
          class="confirm-bar line-height-80 padding-lr-30 bg-ff border-bottom-ed flex align-center justify-between"
        >
          <view class="text-cc" @click="is_area_show = false">取消</view>
          <view class="" style="color: #007aff" @click="adresSubmit()"
            >确定</view
          >
        </view>
        <picker-view
          :value="multiIndex"
          :indicator-style="indicatorStyle"
          class="picker-view"
          @change="changeAdres"
        >
          <picker-view-column>
            <view
              class="item-pircker"
              v-for="(item, index) in arealist1"
              :key="index"
              >{{ item.name }}</view
            >
          </picker-view-column>
          <picker-view-column v-if="arealist2">
            <view
              class="item-pircker"
              v-for="(item, index) in arealist2"
              :key="index"
              >{{ item.name }}</view
            >
          </picker-view-column>
          <picker-view-column v-if="arealist3">
            <view
              class="item-pircker"
              v-for="(item, index) in arealist3"
              :key="index"
              >{{ item.name }}</view
            >
          </picker-view-column>
        </picker-view>
      </view>
    </view> -->
        <!-- <view class="wrap">
      <view class="wrap-list">
        <block v-for="(item, index) in list" :key="index">
          <view class="item">
            <view class="top">
              <input
                class="input"
                type="text"
                v-model="item.name"
                placeholder="请输入规格类型"
                placeholder-style="color:#999;"
              />

              <view class="delete" @click="onDelete(index)">删除</view>
            </view>

            <view class="sku-list" v-if="item.sku.length > 0">
              <block v-for="(subItem, subIdex) in item.sku" :key="index">
                <view class="sku-item">
                  <input
                    class="input"
                    type="text"
                    placeholder="输入"
                    placeholder-style="color:#999;"
                    @blur="onEnd"
                    :value="subItem.name"
                    @input="onSKUInput($event, index, subIdex)"
                  />
                  ·
                  <view @click="onSKUDelete(index, subIdex)"> 删除 </view>
                </view>
              </block>
            </view>

            <view class="add" @click="skuAdd(index)">添加</view>
          </view>
        </block>
      </view>

      <view class="wrap-btn" @click="onAdd"> 添加规格 </view>
    </view>
    <view class="item item_pad_bot padding-bottom-30">
      <view class="it_right_duo" v-for="(item, index) in AAAlist" :key="index">
        <view class="u-flex u-flex-wrap" style="margin-top: 20rpx">
          <view
            class="it_pri"
            v-for="(items, indexs) in item.sku"
            :key="indexs"
            >{{ items }}</view
          >
        </view>
        <view class="u-flex u-row-between it_rig_line">
          <block v-for="(subItem, subIndex) in item.list" :key="subIndex">
            <view class="it_ban u-flex">
              <view class="it_left">{{ subItem.title }}</view>
              <input
                type="number"
                placeholder="请输入价格"
                v-model="subItem.price"
              /> </view
          ></block>
        </view>
      </view>
    </view> -->
        <!-- 发布 -->
        <view class="add1 btn u-flex-center" @click="getSubmit()"
            >确认发布</view
        >
        <view style="height: 30rpx"></view>
        <!-- 一级分类 -->
        <u-picker
            range-key="name"
            v-model="is_cate_show"
            @confirm="confirmIt"
            mode="selector"
            :range="selector"
        ></u-picker>
        <!-- 二级分类 -->
        <u-picker
            range-key="name"
            v-model="show_cate_is"
            @confirm="confirmIt2"
            mode="selector"
            :range="catelist2"
        ></u-picker>
        <!-- 运费模板 -->
        <u-picker
            range-key="name"
            v-model="is_yunfei_show"
            @confirm="confirmYunFei"
            mode="selector"
            :range="postagelist"
        ></u-picker>
        <!-- 店铺分类 -->
        <!-- range-key="name" -->
        <u-picker
            range-key="name"
            v-model="showFenLei"
            @confirm="confirmFenLei"
            mode="selector"
            :range="fenleiList"
        ></u-picker>
        <!-- 省市区选择器 -->
        <u-select
            v-model="show_area_is"
            mode="mutil-column-auto"
            label-name="name"
            value-name="id"
            :list="areaList"
            @confirm="confirmArea"
        ></u-select>
    </view>
</template>

<script>
import { imageURL } from "../../utils/config.js";
import { BaseUrl } from "../../utils/req.js";
// import address :from "imageURL+/components/w-picker/areadata/areadata.js"
export default {
    // components: {
    // 	address
    // },
    data() {
        return {
            BaseUrl,
            list: [], //多规格列表
            AAAlist: [], //最后的数组
            items: [
                {
                    value: "1",
                    name: "新品",
                },
                {
                    value: "2",
                    name: "热销",
                },
            ],
            selector: [],
            showFenLei: false,
            imageURL,
            signShow: true,
            is_add_show: false,
            show_area_is: false, //省市区选择器
            areaList: [], //省市区列表
            skuList: [],
            newSpec: "",
            PricList: [],
            //选择分类
            catelist1: [], //一级分类
            catelist2: [], //二级分类
            catelist3: [],
            multiIndex: [0, 0, 0],
            multiArray: [],
            indicatorStyle: "height: 80rpx;",
            cateid: "",
            is_cate_show: false, //是否显示一级分类
            show_cate_is: false, //是否显示二级分类
            catename: "",
            //邮费
            postagelist: [],
            postageid: "",
            postagename: "",
            // 城市地区
            arealist1: [],
            arealist2: [],
            arealist3: [],
            areaname: "",
            is_area_show: false,
            cover_img: "",
            coverup: "",
            video: "",
            imagelist: [],
            videolist: [],
            title: "",
            id: "",
            catenamelist: [], //分类
            level: 0, //分类层级
            yijiName: "", //一级分类
            erjiName: "", //二级分类
            yijiId: null, //一级分类id
            erjiId: null, //二级分类id
            postagelist: [], //运费模板
            ssqName: "", //省市区
            imgUrl: [], //页面展示图片路径
            imageUrl: "", //传走的图片路径
            images: [], //传走的图片路径
            addSKU: [], //多规格
            videoItem: "", //页面展示的视频（原为数组）
            videoUrl: "", //传走的视频（原为数组）
            fenleiList: [], //店铺内分类
            fenleiName: "", //店铺内分类标题
            fenleiId: null, //店铺内分类id
            description: "", //描述
            content: "", //详情
            province: "", //省
            city: "", //市
            district: "", //区
        };
    },
    onLoad(options) {
        this.id = options.id ? options.id : "";
        if (options.id) {
            uni.setNavigationBarTitle({
                title: "修改产品",
            });
        }
        // this.getcatelist2();
    },
    onShow() {
        this.getcatelist1(); // 获取一级分类
        this.getcatelists();
        this.postage(); //运费模板
        this.area(); //省市区
    },

    methods: {
        // 获取店铺分类
        async getcatelists() {
            const res = await this.$request.post(
                "api/wanlshop.merchant/get_shop_sort_list"
            );
            this.fenleiList = res.data.data;
            console.log(this.fenleiList, "店铺分类");
        },
        // 选择店铺分类
        confirmFenLei(e) {
            console.log(e, "选择店铺分类");
            this.fenleiName = this.fenleiList[e].name;
            this.fenleiId = this.fenleiList[e].id;
        },
        //多规格
        //大删除
        onDelete(index) {
            this.list.splice(index, 1);
            this.$set(this.list);
            this.onEnd();
        },
        //小添加
        skuAdd(index) {
            let item = {
                name: "",
            };
            this.list[index].sku.push(item);
            this.$set(this.list);
        },
        //大添加
        onAdd() {
            let item = {
                name: "",
                sku: [],
            };
            this.list.push(item);
        },
        //小删除
        onSKUDelete(index, subIdx) {
            console.log(index, subIdx, "------------------------");
            uni.showModal({
                title: "是否删除",
                success: (res) => {
                    if (res.confirm) {
                        this.list[index].sku.splice(subIdx, 1);
                        this.$set(this.list);
                        this.onEnd();
                    }
                },
            });
        },
        //输入
        onSure() {
            let count = 0;
            for (let i = 0; i < this.list.length; i++) {
                let item = this.list[i];
                if (item.name == "") {
                    count++;
                }
                for (let j = 0; j < item.sku.length; j++) {
                    let subItem = item.sku[j];
                    if (subItem.name == "") {
                        count++;
                    }
                }
            }
            if (count > 0) {
                //提示 有没有输入的
            } else {
            }
        },
        //多规格
        async onEnd() {
            console.log(234);
            let skuList = await this.getSkuListData();

            let lastArray = await this.getLastArray(skuList);
            console.log("最后的数组", lastArray);
            let AAAlist = [];
            for (let i = 0; i < lastArray.length; i++) {
                let item = lastArray[i];
                let obj = {
                    sku: item.split(","),
                    list: [
                        {
                            title: "原价",
                            price: "",
                        },
                        {
                            title: "现价",
                            price: "",
                        },
                        {
                            title: "会员价",
                            price: "",
                        },
                        {
                            title: "重量(k)",
                            price: "",
                        },
                        {
                            title: "编码",
                            price: "",
                        },
                    ],
                };
                AAAlist.push(obj);
            }
            this.AAAlist = AAAlist;
        },
        // 获取最后的数组
        getLastArray(skuList) {
            return new Promise(async (resolve) => {
                let lastArray = [];
                for (let i = 0; i < skuList.length; i++) {
                    let item = skuList[i];
                    lastArray = await this.calculation(item, lastArray);
                    // lastArray = bArray
                    if (i == skuList.length - 1) {
                        resolve(lastArray);
                    }
                }
            });
        },
        // 计算
        calculation(item, oneArray) {
            return new Promise((resolve) => {
                let bArray = [];
                for (let i = 0; i < item.length; i++) {
                    let subItem = item[i];
                    if (oneArray.length == 0) {
                        bArray.push(subItem);
                    } else {
                        for (let j = 0; j < oneArray.length; j++) {
                            let nextSubItem = oneArray[j];
                            let value = nextSubItem + "," + subItem;
                            bArray.push(value);
                        }
                    }
                    if (i == item.length - 1) {
                        resolve(bArray);
                    }
                }
            });
        },
        /**
         * 获取sku数组
         */
        getSkuListData() {
            return new Promise((resolve) => {
                let skuList = [];
                for (let i = 0; i < this.list.length; i++) {
                    let item = this.list[i];
                    let array = [];
                    for (let j = 0; j < item.sku.length; j++) {
                        let subItem = item.sku[j];
                        let sku = subItem.name;
                        if (sku != "") {
                            array.push(sku);
                        }
                    }
                    skuList.push(array);

                    if (i == this.list.length - 1) {
                        resolve(skuList);
                    }
                }
            });
        },
        // 获取子规格输入框
        onSKUInput(e, index, subIdx) {
            this.list[index].sku[subIdx].name = e.detail.value;
            this.$set(this.list);
        },
        //旧的
        yiji() {
            this.is_cate_show = true;
            this.selector = this.catelist1;
            this.level = 1;
        },
        // 获取一级分类
        async getcatelist1() {
            await this.$request
                .get("api/wanlshop.merchant/get_goods_category")
                .then((res) => {
                    console.log(res, "一级分类");
                    this.catelist1 = res.data;
                });
        },
        // // 获取二级分类
        // async getcatelist2(id) {
        //     await this.$request
        //         .get("api/index/getGoodsCagory", {
        //             pid: id,
        //         })
        //         .then((res) => {
        //             console.log(res, "二级分类");
        //             this.catelist2 = res.data;
        //             console.log(this.catelist2, "二级分类3");
        //         });
        // },
        // 一级分类
        confirmIt(e) {
            this.yijiName = this.selector[e].name;
            this.yijiId = this.selector[e].id;
            this.catelist1.map((item) => {
                if (item.id == this.yijiId) {
                    this.catelist2 = item.children;
                    if(item.children.length == 0){
                        this.erjiId = item.id;
                    }
                }
            })
            this.erjiId = "";
            this.erjiName = "";
            console.log(
                this.yijiId,
                "yijiId",
                this.yijiName,
                "yijiName",
                "一级分类"
            );
            // this.getcatelist2(this.yijiId); //传id获取二级分类
        },
        // 二级分类
        confirmIt2(e) {
            this.erjiName = this.catelist2[e].name;
            this.erjiId = this.catelist2[e].id;
            console.log(
                this.erjiId,
                "erjiId",
                this.erjiName,
                "erjiName",
                "二级分类"
            );
            this.show_cate_is = false;
        },
        //运费模板
        postage() {
            this.$request
                .post("/api/wanlshop.merchant/get_logistics_list")
                .then((res) => {
                    this.postagelist = res.data.data;
                });
        },
        // 运费模板选择
        getPostage(e) {
            this.postageid = this.postagelist[e.detail.value].id;
            this.postagename = this.postagelist[e.detail.value].name;
            console.log(
                this.postagename,
                "postagename",
                this.postageid,
                "postageid",
                "运费模板"
            );
        },
        //省市区
        async area() {
            await this.$request
                .post("/api/wanlshop.merchant/area_list")
                .then((res) => {
                    console.log(res, "省市区");
                    this.areaList = res.data;
                });
        },
        //省市区确定
        confirmArea(e) {
            this.ssqName = "";
            console.log(e, "省市区选择器");
            e.forEach((item, index) => {
                if (index !== e.length) {
                    this.ssqName += item.label + " ";
                } else {
                    this.ssqName += item.label;
                }
                this.province = e[0].label;
                this.city = e[1].label;
                this.district = e[2].label;
            });
            console.log(this.ssqName, "ssqName", "省市区");
        },
        //删除
        delAdd() {
            this.newSpec = "";
            this.is_add_show = false;
        },
        // 添加新规格
        iptNewspec(e) {
            console.log(e);
            var arr = {
                title: "",
                skuitem: [],
            };
            arr.title = e.detail.value;
            this.skuList.push(arr);
            console.log(this.skuList);
            this.newSpec = "";
            this.is_add_show = false;
        },
        // 删除规格
        skuDel(index) {
            var dellist = this.skuList;
            dellist.splice(index, 1);
            console.log(dellist, "dellist");
            this.PricList = []; //7加（去掉大规格，下面小规格一起删掉）
        },
        //规格名
        iptitSpec(indexs) {
            console.log(indexs, "indexs");
            console.log(this.skuList, "规格名");
            this.getPricelist();
        },
        //添加规格名
        addSpec(skuitem, index) {
            console.log(skuitem);
            var arr = {
                name: "",
            };
            var newskuitm = skuitem;
            newskuitm.push(arr);
            for (let i = 0; i < this.skuList.length; i++) {
                if (index == i) {
                    this.skuList[i].skuitem = newskuitm;
                }
            }
            console.log(this.skuList, "sku");
        },
        //删除规格名
        delSpec(indexs, skuitem) {
            var newskuitm = skuitem;
            newskuitm.splice(indexs, 1);
            for (let i = 0; i < this.skuList.length; i++) {
                if (indexs == i) {
                    this.skuList[i].skuitem = newskuitm;
                }
            }
            console.log(this.skuList, "sku");
        },
        //生成价格列表
        getPricelist() {
            var ayy = [];

            for (let i = 0; i < this.skuList.length; i++) {
                var temp_p = [];
                for (let j = 0; j < this.skuList[i].skuitem.length; j++) {
                    if (ayy.length == 0) {
                        temp_p.push(this.skuList[i].skuitem[j].name);
                    } else {
                        for (var t = 0; t < ayy.length; t++) {
                            temp_p.push(
                                ayy[t] + "," + this.skuList[i].skuitem[j].name
                            );
                        }
                    }
                }
                ayy = temp_p;
            }

            this.last(ayy);
        },
        async last(ayy) {
            console.log(ayy);
            const add = {
                temp: [],
            };

            const newList = ayy.map((v, i) => {
                return {
                    temp: v.split(","),
                    price: "",
                    kuc: "",
                    weigh: "",
                    market_price: "",
                    vip_price: "",
                    sn: "",
                };
            });

            this.PricList = newList;
            console.log(this.PricList);
        },
        change(e) {
            let curMultiIndex = e.detail.value;
            if (curMultiIndex[0] != this.multiIndex[0]) {
                this.multiIndex = [curMultiIndex[0], 0, 0];
            } else if (curMultiIndex[1] != this.multiIndex[1]) {
                this.multiIndex = [this.multiIndex[0], curMultiIndex[1], 0];
            } else if (curMultiIndex[2] != this.multiIndex[2]) {
                this.multiIndex = [
                    this.multiIndex[0],
                    this.multiIndex[1],
                    curMultiIndex[2],
                ];
            }
            console.log(this.multiIndex);
            var i = this.multiIndex[0];
            var j = this.multiIndex[1];
            var k = this.multiIndex[2];
            this.catelist2 = this.catelist1[i].children;
            this.catelist3 = this.catelist1[i].children[j].children;

            console.log(this.cateid);
        },
        cateSubmit() {
            var i = this.multiIndex[0];
            var j = this.multiIndex[1];
            var k = this.multiIndex[2];
            if (this.catelist3.length) {
                this.catename =
                    this.catelist1[i].name +
                    "," +
                    this.catelist1[i].children[j].name +
                    "," +
                    this.catelist1[i].children[j].children[k].name;
                this.cateid = this.catelist1[i].children[j].children[k].id;
            } else if (this.catelist2.length) {
                this.catename =
                    this.catelist1[i].name +
                    "," +
                    this.catelist1[i].children[j].name;
                this.cateid = this.catelist1[i].children[j].id;
            } else if (this.catelist1.length) {
                this.catename = this.catelist1[i].name;
                this.cateid = this.catelist1[i].id;
            }

            this.is_cate_show = false;
        },

        changeAdres(e) {
            let curMultiIndex = e.detail.value;
            if (curMultiIndex[0] != this.multiIndex[0]) {
                this.multiIndex = [curMultiIndex[0], 0, 0];
            } else if (curMultiIndex[1] != this.multiIndex[1]) {
                this.multiIndex = [this.multiIndex[0], curMultiIndex[1], 0];
            } else if (curMultiIndex[2] != this.multiIndex[2]) {
                this.multiIndex = [
                    this.multiIndex[0],
                    this.multiIndex[1],
                    curMultiIndex[2],
                ];
            }
            console.log(this.multiIndex);
            var i = this.multiIndex[0];
            var j = this.multiIndex[1];
            var k = this.multiIndex[2];
            this.arealist2 = this.arealist1[i].children;
            this.arealist3 = this.arealist1[i].children[j].children;
            console.log(this.cateid);
        },
        adresSubmit() {
            var i = this.multiIndex[0];
            var j = this.multiIndex[1];
            var k = this.multiIndex[2];
            this.areaname =
                this.arealist1[i].name +
                "/" +
                this.arealist1[i].children[j].name +
                "/" +
                this.arealist1[i].children[j].children[k].name;
            this.is_area_show = false;
        },
        //上传图片
        upshopImg() {
            uni.chooseImage({
                count: 1,
                success: async (res) => {
                    const tempFilePaths = res.tempFilePaths;
                    await uni.uploadFile({
                        url: BaseUrl + "/api/common/upload",
                        filePath: tempFilePaths[0],
                        name: "file",
                        header: {
                            token: uni.getStorageSync("token"),
                            "content-type": "multipart/form-data",
                        },
                        success: (res1) => {
                            this.imgUrl.push(
                                JSON.parse(res1.data).data.fullurl
                            );
                            if (this.imageUrl == "") {
                                this.imageUrl = JSON.parse(res1.data).data.url;
                            }
                            this.images.push(JSON.parse(res1.data).data.url);
                            console.log(
                                JSON.parse(res1.data).data,
                                "------------------"
                            );
                        },
                    });
                },
            });
        },
        uplistImg() {
            uni.chooseVideo({
                sourceType: ["camera", "album"],
                compressed: false,
                data: {
                    name: "1",
                },
                success: (res) => {
                    console.log(res, "视频--------------------------");
                    uni.uploadFile({
                        url: BaseUrl + "/api/common/upload",
                        filePath: res.tempFilePath,
                        name: "file",
                        header: {
                            token: uni.getStorageSync("token"),
                            "content-type": "multipart/form-data",
                        },

                        success: (res) => {
                            console.log(JSON.parse(res.data).data, "上传视频");
                            // this.videoItem.push(JSON.parse(res.data).data.fullurl);
                            // this.videoUrl.push(JSON.parse(res.data).data.url);
                            this.videoItem = JSON.parse(res.data).data.fullurl;
                            console.log("上传的视频", res.data.fullurl);
                            this.videoUrl = JSON.parse(res.data).data.url;
                        },
                    });
                },
            });
        },
        getSc(index) {
            var newlist = this.imagelist;
            newlist.splice(index, 1);
            this.imagelist = newlist;
        },
        getSubmit() {
            if (!this.fenleiName) {
                uni.showToast({
                    title: "请选择商品分类",
                    icon: "none",
                });
                return;
            }
            this.$request
                .post("/api/wanlshop.merchant/add_goods", {
                    title: this.title,
                    category_id: this.erjiId,
                    image: this.imageUrl,
                    images: this.images,
                    video: this.videoUrl,
                    city: this.ssqName,
                    shop_category_id: this.fenleiId,
                    freight_id: this.postageid,
                    spu: this.skuList,
                    sku: this.PricList,
                    ids: this.id,
                    description: this.description,
                    content: this.content,
                    province: this.province,
                    // city: this.city,
                    district: this.district,
                })
                .then((res) => {
                    uni.showToast({
                        title: "商品提交成功",
                        //将值设置为 success 或者直接不用写icon这个参数
                        icon: "none",
                        //显示持续时间为 2秒
                        duration: 3000,
                    });
                    setTimeout(() => {
                        uni.navigateBack();
                    }, 1000);
                })
                .catch((err) => {
                    uni.showToast({
                        title: err.msg,
                        icon: "none",
                    });
                });
            // console.log(res.code, "添加商品");
            // if (res.code == 1) {
            //     //(改)
            // } else {
            //     console.log(res, "失败-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            // }
        },
    },
};
</script>

<style lang="scss" scoped>
/* 多规格 */
.wrap {
    width: 100%;
    padding: 20rpx;
    overflow: hidden;

    .wrap-list {
        margin: 20rpx auto;
        width: 700rpx;
        background-color: white;
        overflow: hidden;
        border-radius: 20rpx;

        .item {
            padding: 20rpx;
            width: 100%;
            box-sizing: border-box;
            margin-bottom: 20rpx;
            overflow: hidden;
        }

        .top {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;

            input {
                text-align: left;
            }

            .delete {
                font-size: 28rpx;
                color: #333;
            }
        }

        .sku-list {
            margin-top: 20rpx;
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;

            .sku-item {
                width: 200rpx;
                height: 100rpx;
                margin-bottom: 30rpx;

                input {
                    text-align: left;
                }
            }
        }

        .add {
            width: 200rpx;
            height: 50rpx;
            border: 2rpx solid #00a67a;
            padding: 10rpx 20rpx;
            color: #00a67a;
        }
    }

    .input {
        flex: 1;
        height: 60rpx;
    }

    .wrap-btn {
        margin: 20rpx auto;
        width: 400rpx;
        height: 100rpx;
        line-height: 100rpx;
        text-align: center;
        background-color: green;
        border-radius: 50rpx;
        overflow: hidden;
        color: white;
        font-size: 32rpx;
    }
}

/* //旧的 */
page {
    width: 100%;
    padding: 0 33rpx;
    box-sizing: border-box;
}

@import url(@/components/common.css);

.home {
    width: 100%;
    min-height: 100vh;
    padding-top: 30rpx;
}

.top {
    padding: 30rpx 0;

    .title {
        font-size: 32rpx;
        font-weight: bold;
        color: #333;
    }

    .radius {
        width: 32rpx;
        height: 32rpx;
        border-radius: 50%;
        margin-right: 10rpx;
        border: 1rpx solid #888;
    }

    .rad_css {
        background: #606dce;
        border: 1rpx solid #606dce;
    }

    .grey {
        color: #333;
        font-size: 28rpx;
    }
}

.it_flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.item_pad_bot {
    padding-bottom: 10rpx !important;
}

.item {
    padding: 32rpx 30rpx;
    background: #fff;
    font-size: 28rpx;
    border-radius: 10rpx;
    margin-bottom: 20rpx;
    box-sizing: border-box;

    .it_left {
        font-weight: bold;
        color: #222;
    }

    input {
        font-size: 28rpx;
        text-align: right;
    }

    .it_right {
        display: flex;
        align-items: center;

        text {
            color: #222;
        }

        .it_lef_img {
            width: 10rpx;
            height: 20rpx;
            margin-left: 10rpx;
        }

        .it_rig_img {
            width: 220rpx;
            height: 220rpx;
            border-radius: 20rpx;
            margin-right: 10rpx;
            margin-bottom: 10rpx;
        }

        .it_rig_box {
            width: 220rpx;
            height: 220rpx;
            border-radius: 20rpx;
            margin-right: 10rpx;
            margin-bottom: 10rpx;
            background: #f7f7f7;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #c9c9c9;
            font-size: 84rpx;

            image {
                width: 60rpx;
                height: 60rpx;
            }
        }
    }

    .it_right_duo {
        border-bottom: 1rpx solid #dfdfdf;

        &:last-child {
            border: none;
        }
    }

    .it_tit {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: 30rpx;
        margin-bottom: 30rpx;
        border-bottom: 1rpx solid #f5f5f5;

        .it_grey {
            font-size: 28rpx;
            color: #888;

            image {
                width: 28rpx;
                height: 28rpx;
                margin-right: 10rpx;
            }
        }

        input {
            font-size: 28rpx;
            font-weight: bold;
            text-align: left;
        }
    }

    .it_specs {
        color: #222;
        display: flex;
        font-size: 24rpx;
        align-items: center;
        padding: 10rpx 40rpx;
        background: #f5f5f5;
        border-radius: 26rpx;
        margin-right: 30rpx;
        margin-bottom: 20rpx;

        .it_sp_line {
            width: 2rpx;
            height: 24rpx;
            margin: 0 20rpx 0 24rpx;
        }

        .it_sp_cha {
            width: 20rpx;
            height: 20rpx;
        }

        .it_sp_plus {
            width: 20rpx;
            height: 20rpx;
            margin-right: 20rpx;
        }

        .it_sp_gre {
            color: #606dce;
        }
    }

    .it_specs input {
        flex: 1;
        max-width: 60rpx;
    }

    .it_pri {
        font-size: 24rpx;
        color: #222;
        padding: 10rpx 48rpx;
        background: #f5f5f5;
        margin-right: 30rpx;
    }

    .it_ban {
        width: 50%;
        padding: 30rpx 0;

        input {
            flex: 1;
            text-align: left;
            margin-left: 20rpx;
        }
    }
}

.btn {
    width: 630rpx;
    height: 80rpx;
    margin-top: 157rpx;
}

.layer {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.layer-content {
}

/* 浮层内容 */
.confirm-bar {
    position: fixed;
    bottom: 600rpx;
    left: 0;
    width: 750rpx;
}

.line-height-80 {
    height: 80rpx;
    line-height: 80rpx;
}

.padding-lr-30 {
    padding-left: 30rpx;
    padding-right: 30rpx;
}

.bg-ff {
    background: #fff;
}

.border-bottom-ed {
    border-bottom: 1rpx solid #ededed;
}

.flex {
    display: flex;
}

.align-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.picker-view {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 750rpx;
    height: 600rpx;
    background: #fff;
}

.item-pircker {
    line-height: 80rpx;
    height: 80rpx;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.scimg {
    width: 45rpx;
    height: 45rpx;
    position: absolute;
    top: -20rpx;
    right: -20rpx;
}

.textarea {
    height: 80rpx;
}

.add {
    width: 200rpx;
    height: 60rpx;
    font-size: 28rpx;
    color: #fff;
    margin: 0 auto;
    margin-top: 30rpx;
    background: linear-gradient(135deg, #2bb984 0%, #8cd994 100%);
    border-radius: 40rpx;
}

.add1 {
    width: 80%;
    height: 80rpx;
    font-size: 28rpx;
    color: #fff;
    margin: 0 auto;
    margin-top: 30rpx;
    background: linear-gradient(#00aa6c 0%, #007c0c 100%);
    border-radius: 40rpx;
}
</style>
